package com.yzs.controller.admin;

import com.yzs.common.bean.R;
import com.yzs.entity.House;
import com.yzs.service.IHouseService;
import com.yzs.service.Impl.HouseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@CrossOrigin
@RequestMapping("/house")
public class HouseController {
    @Autowired
    IHouseService hs = new HouseServiceImpl();

    @RequestMapping("/getHouseByPage")
    public R getHouseByPage(@RequestParam Integer currentPage, @RequestParam Integer pageSize){
        return hs.getHouseByPage(currentPage,pageSize);
    }

    @RequestMapping("/getHouseById")
    public R getHouseById(@RequestParam String id){
        return hs.getHouseById(id);
    }

    @RequestMapping("/uploadPicture")
    public R loadPicture(@RequestParam("files") MultipartFile[] files,HttpServletRequest res){
        String token = res.getHeader("token");
        String houseId = res.getHeader("houseId");
        return hs.uploadPicture(files,token,houseId);
    }

    @RequestMapping("/removePicture")
    public R removePicture(String fileName){
        return hs.removePicture(fileName);
    }

    @RequestMapping("/updateHouseById")
    public R updateHouseById(@RequestBody House house){
        return hs.updateHouseById(house);
    }

    @RequestMapping("/createHouse")
    public R createHouseByAdmin(@RequestBody House house,@RequestParam String token){
        return hs.createHouse(token,house);
    }

    @RequestMapping("/getHouseSale")
    public R getHouseSale(@RequestParam String token,@RequestParam String id){
        return hs.getHouseSale(token,id);
    }
}
